home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / newsgrp / group03a.txt / 000072_icon-group-sender_Tue Apr 15 07:46:16 2003.msg < prev    next >
Internet Message Format  |  2003-12-22  |  2KB

  1. Return-Path: <icon-group-sender>
  2. Received: (from root@localhost)
  3.     by baskerville.CS.Arizona.EDU (8.11.1/8.11.1) id h3FEjAM04078
  4.     for icon-group-addresses; Tue, 15 Apr 2003 07:45:10 -0700 (MST)
  5. Message-Id: <200304151445.h3FEjAM04078@baskerville.CS.Arizona.EDU>
  6. From: Richard Bos <rlb@hoekstra-uitgeverij.nl>
  7. X-Newsgroups: comp.lang.icon
  8. Subject: Re: Simplifying Integer Arithmetic
  9. User-Agent: MT-NewsWatcher/3.1 (PPC)
  10. Date: Tue, 15 Apr 2003 12:22:39 +0200
  11. X-Complaints-To: abuse@nl.uu.net
  12. To: icon-group@cs.arizona.edu
  13. Errors-To: icon-group-errors@cs.arizona.edu
  14. Status: RO
  15.  
  16. In article <b33380$e1o$0@205.153.154.199>,
  17.  Patrick Scheible <kkt@itchy.serv.net> wrote:
  18.  
  19. > "Frank J. Lhota" <NOSPAM.lhota.adarose@verizon.net> writes:
  20. > > The question I pose to this group is whether we should assume that any C
  21. > > compiler used for Icon uses the "round towards 0" method for evaluating a /
  22. > > b and a % b for integers a and b. Given this assumption, we could simplify
  23. > > the div3 and mod3 functions in "runtime/rmisc.r" as follows:
  24. > I would suggest not making any assumptions about which C compilers
  25. > people may use at some point, especially since the work of making Icon
  26. > round towards 0 regardless of the C compiler's behavior has already
  27. > been done.  Who knows what strange platforms someone may wish to port
  28. > Icon to at some point?
  29. > However, I have not done a survey of whether there are any C compilers
  30. > that do not round towards 0.  (Maybe the nice people in comp.lang.c
  31. > happen to know?)
  32.  
  33. Right. I'm a bit late answering this (only just set up the test Mac with 
  34. ProIcon and Newswatcher on it), and I'm not really a c.l.c regular 
  35. anymore, but it's like this:
  36.  
  37. In the first C Standard of 1989, positive/positive division rounded 
  38. towards zero (obviously), and +/+ modulo is positive. However, if either 
  39. operand is negative, the direction of the rounding as well as the sign 
  40. of the modulo is implementation-defined. Even so, for all 
  41. implementations, (a/b)*a + a%b must equal a, as long as a/b can be 
  42. represented at all.
  43. In the new Standard of 1999, this is more closely regulated: all 
  44. implementations that use the new Standard _must_ truncate towards zero. 
  45. This also means that the result of the modulo operator has the same sign 
  46. as its first operand.
  47. I haven't got a large selection of compilers myself, but those I do have 
  48. all round towards zero.
  49.  
  50. Richard
  51.